package cn.ghb.eshop.sys.basic.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;

/**
 * 基础类 - 实体
 *
 * @author Clown
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class BasicEntity {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @TableField(value = "insert_time")
    private LocalDateTime insertTime;

    @TableField(value = "update_time")
    private LocalDateTime updateTime;

    @TableLogic(value = "false", delval = "true")
    @TableField(value = "is_deleted")
    private Boolean deleted;

    public static BasicEntity newInstance() {
        return BasicEntity.builder()
                .insertTime(LocalDateTime.now())
                .updateTime(LocalDateTime.now())
                .deleted(false)
                .build();
    }

}
